﻿using Appliaction.AppServices.Base_Manage;
using Appliaction.Dto.Base_Manage;
using Appliaction.IAppServices.Base_Manage;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RolesController : ControllerBase
    {
        private readonly IRolesService rolesService;
        private readonly IMapper mapper;

        public RolesController(IRolesService rolesService,IMapper mapper)
        {
            this.rolesService = rolesService;
            this.mapper = mapper;
        }

        [HttpGet]
        public  async Task<JsonResult> GetRolesFillAsync()
        {
            return new JsonResult(await rolesService.GetRolesFillAsync());
        }

        /// <summary>
        /// 添加用户角色信息
        /// </summary>
        /// <param name="userRolesAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> UserRolesAddAsync(UserRolesAddDto userRolesAddDto)
        {
            return new JsonResult(await rolesService.UserRolesAddAsync(userRolesAddDto));
        }

        /// <summary>
        /// 根据用户ID删除用户角色信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<JsonResult> UserRolesRemoveAsync(int userId)
        {
            return new JsonResult(await rolesService.UserRolesRemoveAsync(userId));
        }
    }
}
